package com.fuqi.android.zhongcai.base.view.activity.deprecated;


import android.graphics.Color;
import android.util.Log;
import android.view.Gravity;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.LinearLayout;

import com.android.volley.Response;
import com.android.volley.error.VolleyError;
import com.flyco.animation.ZoomEnter.ZoomInEnter;
import com.flyco.animation.ZoomExit.ZoomOutExit;
import com.flyco.dialog.listener.OnBtnClickL;
import com.flyco.dialog.widget.NormalDialog;
import com.fuqi.android.zhongcai.R;
import com.fuqi.android.zhongcai.base.view.activity.BaseActivity;
import com.fuqi.android.zhongcai.business.shuig.view.activity.ShuiGPaiDanActivity;
import com.fuqi.android.zhongcai.business.shuig.request.api.OrderDetailApi;
import com.fuqi.android.zhongcai.business.shuig.request.api.OrderHandleApi;
import com.fuqi.android.zhongcai.business.shuig.request.result.OrderDetailResult;
import com.fuqi.android.zhongcai.business.shuig.request.result.OrderHandleResult;
import com.fuqi.android.zhongcai.base.view.widget.NormalViewDialog;
import com.fuqi.android.zhongcai.utils.ActivityUtils;
import com.fuqi.android.zhongcai.utils.LogUtils;
import com.fuqi.android.zhongcai.utils.OKHttpUtils;
import com.fuqi.framework.gson.GsonHelper;
import com.fuqi.framework.network.code.HandleCode;
import com.fuqi.framework.network.http.RequestManager;

import butterknife.Bind;
import butterknife.OnClick;
@Deprecated
public class OrderDetailNQActivity extends BaseActivity {


    @Bind(R.id.bottom_sgdz)
    LinearLayout bottomSgdz;
    @Bind(R.id.btn_submit)
    Button btnSubmit;
    @Bind(R.id.btn_no_contact)
    Button btnNoContact;
    @Bind(R.id.btn_sure_make_order)
    Button btnMakeOrder;

    private OrderDetailResult orderDetailResult;


    @OnClick({R.id.btn_no_contact,R.id.btn_sure_make_order})
    public void onClick(View v){

            // 内勤
            switch (v.getId()){

                case R.id.btn_no_contact:
                    showBoHuiDialog();
                    break;
                case R.id.btn_sure_make_order:
                    showPaiDanDialog();
                    break;

            }

    }


    public void showBoHuiDialog() {

        final NormalViewDialog dialog = new NormalViewDialog(OrderDetailNQActivity.this);
        final EditText editText = new EditText(OrderDetailNQActivity.this);
        editText.setTextColor(Color.parseColor("#464646"));
        editText.setHint("请输入驳回原因");
        editText.setBackgroundResource(R.drawable.edit_bohui_bg);
        editText.setTextSize(13);
        editText.setSingleLine(true);
        editText.setPadding(10, 30, 10, 30);
        dialog.addContentView(editText);
        dialog.setCanceledOnTouchOutside(false);
        dialog.title("驳回原因 ")
                .titleTextSize(16)
                .style(NormalDialog.STYLE_TWO)
                .titleTextColor(Color.parseColor("#444444"))
                .titleTextSize(16)
                .showAnim(new ZoomInEnter())
                .dismissAnim(new ZoomOutExit())
                .cornerRadius(8)
                .show();



        dialog.setOnBtnClickL(
                new OnBtnClickL() {
                    @Override
                    public void onBtnClick() {
                        dialog.dismiss();
                    }
                },
                new OnBtnClickL() {
                    @Override
                    public void onBtnClick() {

                        if (editText.getText().toString().trim().equals("")) {
                            ActivityUtils.toast("驳回原因不能为空 ");
                        } else {
//                            RequestManager.getInstance().call(new OrderHandleApi(, respOrderBoHuiListener, errorListener));
                              OKHttpUtils.formRequestWithParams(new OrderHandleApi.OrderHandleParams(getIntent().getStringExtra("order__id"),
                                      orderDetailResult.getOrderStatus(),editText.getText().toString().trim(),""));

                        }
                        dialog.dismiss();
                    }
                });



    }


    public void showPaiDanDialog() {
        final NormalDialog dialog = new NormalDialog(OrderDetailNQActivity.this);
        dialog.setCanceledOnTouchOutside(false);
        dialog.content("确定审核通过此订单并派单吗?")
                .style(NormalDialog.STYLE_TWO)
                .title("")
                .titleTextSize(0)
                .contentTextSize(14)
                .contentTextColor(Color.parseColor("#444444"))
                .contentGravity(Gravity.CENTER)
                .showAnim(new ZoomInEnter())
                .dismissAnim(new ZoomOutExit())
                .cornerRadius(8)
                .show();

        dialog.setOnBtnClickL(
                new OnBtnClickL() {
                    @Override
                    public void onBtnClick() {


                        dialog.dismiss();
                    }
                },
                new OnBtnClickL() {
                    @Override
                    public void onBtnClick() {

                        ActivityUtils.startActivity(getApplicationContext(),ShuiGPaiDanActivity.class);
                        dialog.dismiss();

                    }
                });

    }


    Response.Listener<OrderHandleResult> respOrderBoHuiListener = new Response.Listener<OrderHandleResult>() {

        @Override
        public void onResponse(OrderHandleResult response) {

            if (HandleCode.requestSuccess()) {


                Log.i("juner", "juner respListener response : ");
            } else {



            }
        }
    };


    Response.ErrorListener errorListener = new Response.ErrorListener() {

        @Override
        public void onErrorResponse(VolleyError error) {

            Log.i("juner", "juner  error.getMessage(): " + error.getMessage());

        }
    };


    @Override
    public void initView() {

            btnSubmit.setVisibility(View.GONE);
            bottomSgdz.setVisibility(View.VISIBLE);
            btnNoContact.setText("驳回");
            btnMakeOrder.setText("通过并派单");

    }


    @Override
    public void initListener() {

    }

    @Override
    public void initData() {

        titleBar.setTitle("订单详情");
        LogUtils.i("order_id: " + getIntent().getStringExtra("order_id"));
        RequestManager.getInstance().call(new OrderDetailApi(new OrderDetailApi.OrderDetailParams(getIntent().getStringExtra("order_id")),
                respOrderDetailListener, errorListener));

    }

    Response.Listener<OrderDetailResult> respOrderDetailListener = new Response.Listener<OrderDetailResult>() {

        @Override
        public void onResponse(OrderDetailResult response) {

            if (HandleCode.requestSuccess()) {

                orderDetailResult = response;
                Log.i("juner", "juner OrderDetailResult response : " + GsonHelper.writeValue(response));
            } else {



            }
        }
    };


    @Override
    public boolean hasTitleBar() {
        return true;
    }

    @Override
    public int getLayoutId() {
        return R.layout.activity_order_detail_nq;
    }
}
